﻿using Mapster;
using Microsoft.AspNetCore.Mvc;
using WebApi.Common;
using WXQ.BusinessCore;
using WXQ.Enties.CommonObj;
using WXQ.InOutPutEntites.Output;

namespace WebApi.Controllers.LogManage
{
    /// <summary>
    /// 度量日志
    /// </summary>
    [Route("Api/LogManage/Metrics")]
    [WebApi.Common.MiddleWare.Authorize]
    public class MetricsController : BaseController
    {
        /// <summary>
        /// 查找度量日志
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("GetMetricsList")]
        [WebApi.Common.Log]
        public JsonResult GetMetricsList([FromBody] WXQ.InOutPutEntites.Input.LogManage.Metrics.GetMetricsListInput model)
        {
            ResponseResult result = new ResponseResult();

            WXQ.BusinessCore.opLogManager.MetricsOp op = new WXQ.BusinessCore.opLogManager.MetricsOp();

            SqlSugar.PageModel pagemodel = TypeAdapter.Adapt<WXQ.InOutPutEntites.Input.PageInput, SqlSugar.PageModel>(model.Page);
            ListResult<WXQ.Enties.Metrics> rv = op.GetMetricsList(model.MethodName, model.CostTime, model.BgDt, model.EndDt, pagemodel);

            if (rv == null)
            {
                result.Code = ResponseResultMessageDefine.OpLost;
                result.Errors.Add(ResponseResultMessageDefine.OpLostMessage);
            }
            else
            {
                result.Data = rv;
            }

            return Json(result);
        }

        /// <summary>
        /// 删除度量日志
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("Delete")]
        [WebApi.Common.Log]
        public JsonResult Delete([FromBody] WXQ.InOutPutEntites.Input.LogManage.Metrics.MetricsDeleteInput model)
        {
            ResponseResult result = new ResponseResult();

            WXQ.BusinessCore.opLogManager.MetricsOp op = new WXQ.BusinessCore.opLogManager.MetricsOp();

            bool rv = op.Delete(model.MethodName, model.CostTime, model.BgDt, model.EndDt);

            if (!rv)
            {
                result.Code = ResponseResultMessageDefine.OpLost;
                result.Errors.Add(ResponseResultMessageDefine.OpLostMessage);
            }
            else
            {
                result.Data = rv;
            }

            return Json(result);
        }
    }
}